        

        
        function printUser(div_user_id, table_user) {
            var confirm
            if(this.field_confirm!=0)
                confirm = '(!)'
            else
                confirm = ' '
            table_user+= "<div onclick='user_select.changeCellStyle(arguments[0]), " + 
                            '           user_select.rememberFieldData("' + this.field_id + '", "' + this.field_name + '"), ' +
                            '           div_text.addingText(' + '"user: ->"' + ', user_select.name_field), ' + 
                            '           printTime(project_user_tables, ' + 'project_select.id_field, user_select.id_field, "div_time_table"), ' +   
                            "           div_text.insertDivText(" + '"user_select_div"' + ")' " + 
                            "           class='TableCell'> " + 
                                this.field_name + confirm + 
                            "</div>"
            if(this.next_user!=null)
                this.next_user.printUser(div_user_id, table_user)
            else 
                document.getElementById(div_user_id).innerHTML = table_user
        }
        
        function UserField(in_field_name, in_field_id, in_field_confirm) {
            this.field_name = in_field_name
            this.field_id = in_field_id
            this.field_confirm = in_field_confirm
            this.next_user = null
            this.next_time = null

            this.printUser = printUser
        }
        
        function joinSelectedWithTimeFieldNode(time_field_node, user_id, user_name, project_id, project_name) {
            var user_node = project_user_tables.searchTime(project_id, user_id)
            if((String(time_field_node.next_time)!='undefined')&&(user_node.next_time!=null)) {
                var last_time = user_node
                var next_time = user_node.next_time
                var selected_time = null
                var selected_time_temp = null
                var is_first_selected = 1
                
                if(next_time.next_time==null) {
                    if(next_time.is_selected==1) {
                        selected_time = next_time
                        selected_time_temp = selected_time
                        user_node.next_time = null
                    }
                }
                else {
                    while(next_time!=null) {
                        if(next_time.is_selected==1) {
                            if(is_first_selected==1) {
                                selected_time = next_time
                                next_time = next_time.next_time
                                last_time.next_time = next_time
                                selected_time.next_time = null
                                selected_time_temp = selected_time
                                is_first_selected = 0
                            }
                            else {
                                selected_time_temp.next_time = next_time
                                selected_time_temp = selected_time_temp.next_time
                                next_time = next_time.next_time
                                last_time.next_time = next_time
                                selected_time_temp.next_time = null
                            }
                        }
                        else {
                            last_time = next_time
                            next_time = next_time.next_time
                        }
                    }
                }
                if(selected_time_temp!=null) {
                    if((time_field_node.user_id==-1)||(time_field_node.project_id==-1)) {
                        time_field_node.user_id = user_id
                        time_field_node.user_name = user_name
                        time_field_node.project_id = project_id
                        time_field_node.project_name = project_name
                    }
                    else {
                        while(time_field_node.next_time_node!=null) {
                            if((time_field_node.user_id==user_id)&&(time_field_node.project_id==project_id))
                                break
                            time_field_node = time_field_node.next_time_node
                        }
                        if(time_field_node.next_time_node==null) {
                            if((time_field_node.user_id!=user_id)||(time_field_node.project_id!=project_id)) {
                                time_field_node.next_time_node = new  BottomTimeFieldNode(user_id, user_name, project_id, project_name)
                                time_field_node = time_field_node.next_time_node
                            }
                        }
                    }
                    if(time_field_node.next_time!=null) {
                        selected_time_temp.next_time = time_field_node.next_time
                        time_field_node.next_time = selected_time
                    }
                    else
                        time_field_node.next_time = selected_time
                }
            }
        }
        
        function searchTime(project_id, user_id) {
            var project_user_tables_temp
            var project_user_tables_node_temp
            if(this!=null) {
                project_user_tables_node_temp = this
                while(project_user_tables_node_temp!=null) {
                    project_user_tables_temp = project_user_tables_node_temp.next_user
                    while(project_user_tables_temp!=null) {
                        if((project_user_tables_temp.field_id==user_id)&&(project_user_tables_node_temp.field_id==project_id)) {
                            return project_user_tables_temp
                        }
                        project_user_tables_temp = project_user_tables_temp.next_user
                    }
                    project_user_tables_node_temp = project_user_tables_node_temp.next_project
                }
            }
            else 
                return null
        }
        
        function printProject(user_table_node) {
            document.write("<div onclick='project_select.changeCellStyle(arguments[0]), " + 
                            '             project_select.rememberFieldData("' + this.field_id + '", "' + this.field_name + '"), ' +
                            '             user_select.rememberFieldData("-1", "..."), ' +
                                          user_table_node + '.next_user.printUser("div_user", ' + '"<div class=' + 'TableTitle' + '> <center> user: </center> </div>"), ' + 
                            '             printTime(project_user_tables, -1, -1, "div_time_table"), ' + 
                            '             div_text.addingText(' + '"user: ->"' + ', user_select.name_field), ' + 
                            "             div_text.insertDivText(" + '"user_select_div"' + "), " + 
                            '             div_text.addingText(' + '"project: ->"' + ', project_select.name_field), ' + 
                            "             div_text.insertDivText(" + '"project_select_div"' + ")' " + 
                            "             class='TableCell'> " + 
                                this.field_name +
                           "</div>")
            if(this.next_project!=null)
                this.next_project.printProject(user_table_node + '.next_project')
        }
        
        function createTablesTree(time_table, x_project_name, x_project_id, x_user_name, x_user_id) {
            var project_user_temp = this
            var next_user_temp = null
            if(project_user_temp.field_name!=' ') {
                while(project_user_temp!=null) {
                    if(project_user_temp.field_name==x_project_name) {
                        next_user_temp = new UserField(x_user_name, x_user_id, 0)
                        next_user_temp.next_user = project_user_temp.next_user
                        project_user_temp.next_user = next_user_temp
                        break
                    }
                    project_user_temp = project_user_temp.next_project
                }
                if(project_user_temp==null) {
                    project_user_temp = new ProjectUserNode(x_project_name, x_project_id)
                    project_user_temp.next_user = new UserField(x_user_name, x_user_id, 0)
                    next_user_temp = project_user_temp.next_user
                    project_user_temp.next_project = this.next_project
                    this.next_project = project_user_temp
                }
            }
            else {
                project_user_temp.field_name = x_project_name
                project_user_temp.field_id = x_project_id
                project_user_temp.next_user = new UserField(x_user_name, x_user_id, 0)
                next_user_temp = project_user_temp.next_user
            }

            while(time_table!=null) {
                if((time_table.user_id==x_user_id)&&(time_table.project_id==x_project_id)) {
                    next_user_temp.next_time = time_table.next_time
                    next_user_temp.field_confirm = 1
                    break
                }
                time_table = time_table.next_time_node
            }
        }
        
        function ProjectUserNode(in_field_name, in_field_id) {
            this.field_name = in_field_name
            this.field_id = in_field_id
            this.next_project = null
            this.next_user = null
            
            this.printProject = printProject
            this.searchTime = searchTime
            this.createTablesTree = createTablesTree
            this.joinSelectedWithTimeFieldNode = joinSelectedWithTimeFieldNode
        }
        
        
        var project_user_tables = new ProjectUserNode(' ', ' ')
